package nz.ac.massey.cs.se400_2013.ass3.plugin;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextField;

public class AddressEditorUi extends BasicEditor{

	private JTextField streetEntry;
	private JSpinner noEntry;
	private JTextField cityEntry;
	private JLabel streetLabel;
	private JLabel noLabel;
	private JLabel cityLabel;
	
	public AddressEditorUi(){
		streetLabel = new JLabel("city");
		streetEntry = new JTextField();
		noLabel = new JLabel("number");
		noEntry = new JSpinner();
		cityLabel = new JLabel("City");
		cityEntry = new JTextField();
		
		GridBagLayout layout = new GridBagLayout();
		this.setLayout(layout);
		this.addCity();
		this.addStreet();
		this.addNo();
		
		this.addChangeHandlers();
	}
	
	public void addStreet(){
		GridBagConstraints constraints = new GridBagConstraints();
		constraints.anchor = GridBagConstraints.SOUTHWEST;
		constraints.gridx = 0;
		constraints.gridy = 0;
		constraints.ipadx = 100;
		
		this.add(this.streetLabel, constraints);
		
		constraints.gridx = 1;
		constraints.gridy = 0;
		this.add(this.streetEntry, constraints);
	}
	
	public void setStreet(String text){
		this.streetEntry.setText(text);
	}
	
	public String getStreet(){
		return this.streetEntry.getText();
	}
	
	public void setNo(int i){
		this.noEntry.setValue(i);
	}
	
	public int getNo(){
		return (Integer)this.noEntry.getValue();
	}
	
	public void setCity(String city){
		this.cityEntry.setText(city);
	}
	
	public String getCity(){
		return this.cityEntry.getText();
	}
	
	public void addCity(){
		GridBagConstraints constraints = new GridBagConstraints();
		constraints.anchor = GridBagConstraints.SOUTHWEST;
		constraints.gridx = 0;
		constraints.gridy = 1;
		constraints.ipadx = 100;
		
		this.add(this.cityLabel, constraints);
		
		constraints.gridx = 1;
		constraints.gridy = 1;
		this.add(this.cityEntry, constraints);
	}
	
	public void addNo(){
		GridBagConstraints constraints = new GridBagConstraints();
		constraints.anchor = GridBagConstraints.SOUTHWEST;
		constraints.gridx = 0;
		constraints.gridy = 2;
		this.add(this.noLabel, constraints);
		
		constraints.gridx = 1;
		constraints.gridy = 2;
		this.add(this.noEntry, constraints);
	}
	
}